package com.qtcm.nas.spc.shouhouguanli.web;

import com.qtcm.nas.spc.pojo.Asmanagement_Out;
import com.qtcm.nas.spc.pojo.Car_Out;
import com.qtcm.nas.spc.shouhouguanli.service.ImpShouHouService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Description说明: 售后管理
 * @Date 2022/7/16 9:04
 * @PackageName:com.jzyh.spc.login.service
 * @ClassName: ImpUserService
 * @Author作者: Spc
 * @Version 1.0
 * @自己写的注释: 售后管理一
 */
@Controller("shouHuoController")
@RequestMapping(value = "/shouhou")
public class ShouHuoController {
    @Autowired
    @Qualifier("shouHouService")
    private ImpShouHouService shouHouService;

    @RequestMapping(value = "/findShou")
    public String findShou(Model model) {
//        根据多个表查询出来的数据
        List<Asmanagement_Out> list = shouHouService.findShou();
/*        for (Asmanagement_Out asmanagement_Out : list) {
            Asmanagement_Out asmanagement_Out1=new Asmanagement_Out();
            asmanagement_Out1.setC_name(asmanagement_Out.getC_name());
            asmanagement_Out1.setC_membernumber(asmanagement_Out.getC_membernumber());
            asmanagement_Out1.setC_mileage(asmanagement_Out.getC_mileage());
            asmanagement_Out1.setE_order_remarks(asmanagement_Out.getE_order_remarks());
            asmanagement_Out1.setC_phone(asmanagement_Out.getC_phone());
            asmanagement_Out1.setC_ipnumber(asmanagement_Out.getC_ipnumber());
            asmanagement_Out1.setE_Billig_date(asmanagement_Out.getE_Billig_date());
            asmanagement_Out1.setF_service_name(asmanagement_Out.getF_service_name());
            asmanagement_Out1.setE_money(asmanagement_Out.getE_money());
        }*/
        int a = list.size();
        Asmanagement_Out asmanagement_OutPan = list.get(a - 1);
        List<Asmanagement_Out> listZong = shouHouService.findZong();
        int b = listZong.size();
        Asmanagement_Out asmanagement_Outzong = listZong.get(b - 1);
//        在这里进行判断车牌号  如果最后一个车牌号不相等的话 就进行添加
        if (asmanagement_Outzong.getC_ipnumber().equals(asmanagement_OutPan.getC_ipnumber())) {
            model.addAttribute("listZong", listZong);
            return "afterSales_List";
        } else {
            shouHouService.addShou(asmanagement_OutPan);
            model.addAttribute("listZong", listZong);
            return "afterSales_List";
        }

    }

    @RequestMapping("/dataFind")
    public String dataFind(String start, String end, Model model, String order_code, String service) {
        String humo = "%" + order_code + "%";
        List<Asmanagement_Out> list = shouHouService.findZong(start, end, humo, service);
        model.addAttribute("start", start);
        model.addAttribute("end", end);
        model.addAttribute("order_code", order_code);
        model.addAttribute("service", service);
        model.addAttribute("listZong", list);
        return "afterSales_List";
    }

    //    新增售后
    @RequestMapping("/sousuo")
    public String chaxun(String nanec, Model model, HttpSession session) {
        List<String> listName = shouHouService.findHuiYuan(nanec);
        model.addAttribute("namec", nanec);
        model.addAttribute("listName", listName);
//        根据会员姓名查询车牌号
        List<Car_Out> listCar = shouHouService.findCar(nanec);
        System.out.println("车牌号数据的长度为:" + listCar.size());
        model.addAttribute("listCar", listCar);
        return "add_afterSales";
    }

    //    进行添加
    @RequestMapping("/add")
    public String addShouhou(HttpServletRequest request) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        获取姓名
        String name=request.getParameter("nanes");
        System.out.println(name);
        int bianhao=shouHouService.findBian(name);
        System.out.println("编号为: "+bianhao);
        String phone=shouHouService.findPhone(name);
        System.out.println("手机号为: "+phone);
        String fuwu=request.getParameter("service_id");
        System.out.println("服务为: "+fuwu);
        String c_ipnumber = request.getParameter("c_ipnumber");
        System.out.println("车牌号为"+c_ipnumber);
        String price=request.getParameter("pricein");
        System.out.println("服务的价格为:" +price);
        String beizhu=request.getParameter("remark");
        System.out.println("备注为: "+beizhu);
        String licheng=request.getParameter("licheng");
        System.out.println("里程数为: "+licheng);
        Asmanagement_Out asmanagement_Out=new Asmanagement_Out();
        asmanagement_Out.setC_name(name);
        asmanagement_Out.setC_membernumber(bianhao);
        asmanagement_Out.setC_mileage(licheng);
        asmanagement_Out.setE_order_remarks(beizhu);
        asmanagement_Out.setC_phone(phone);
        asmanagement_Out.setC_ipnumber(c_ipnumber);
        asmanagement_Out.setE_Billig_date(sdf.format(new Date()));
        asmanagement_Out.setF_service_name(fuwu);
        asmanagement_Out.setE_money(price);
        shouHouService.addShou(asmanagement_Out);
        return "redirect:findShou";
    }
}